import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xuance/RoutePath.dart';
import 'package:xuance/bean/AiWarningitemBean.dart';
import 'package:xuance/bean/SplunkDetailItemBean.dart';
import 'package:xuance/constant.dart';
import 'package:xuance/page/warning_detail/logic.dart';

import 'logic.dart';

class SplunkDetailListPage extends StatelessWidget {
  const SplunkDetailListPage({super.key});

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<SplunkDetailLogic>();
    final state = logic.state;
    return Scaffold(
        backgroundColor: bgColor,
        body: SafeArea(
            child:
                Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
          Padding(
              padding: const EdgeInsets.all(8.0),
              child: Row(children: [
                InkWell(
                    onTap: Get.back,
                    child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Icon(Icons.arrow_back_ios_new_outlined,
                            color: c_CCCCCF))),
                Text("splunk列表",
                    style: TextStyle(color: c_CCCCCF, fontSize: 17))
              ])),
          // Padding(
          //     padding: const EdgeInsets.symmetric(horizontal: 10),
          //     child: Column(children: [
          //       Row(children: [
          //         Expanded(
          //             child: SingleChildScrollView(
          //                 scrollDirection: Axis.horizontal,
          //                 child: Obx(() {
          //                   return Row(
          //                       children: List.generate(
          //                           state.filterTitleList.length, (i) {
          //                     var bean = state.filterTitleList[i];
          //                     return InkWell(
          //                       onTap: () {
          //                         if (state.currentIndex.value == i) {
          //                           state.currentIndex.value = -1;
          //                           state.filter.value = "";
          //                         } else {
          //                           state.currentIndex.value = i;
          //                           state.filter.value = bean.exp.value;
          //                         }
          //                       },
          //                       child: Padding(
          //                           padding: const EdgeInsets.all(8.0),
          //                           child: Row(children: [
          //                             Obx(() {
          //                               return Text(bean.fieldName,
          //                                   style: TextStyle(
          //                                       color: bean.exp.value.isEmpty
          //                                           ? Colors.grey
          //                                           : c_green,
          //                                       fontWeight: FontWeight.bold));
          //                             }),
          //                             Obx(() {
          //                               return Icon(
          //                                   state.currentIndex.value == i
          //                                       ? Icons.arrow_drop_up
          //                                       : Icons.arrow_drop_down,
          //                                   color: bean.exp.value.isEmpty
          //                                       ? Colors.grey
          //                                       : c_green);
          //                             })
          //                           ])),
          //                     );
          //                   }));
          //                 }))),
          //         InkWell(
          //             onTap: () {
          //               Get.toNamed(RoutePath.addFieldFilter,
          //                       arguments: state.filterTitleList)
          //                   ?.then((r) {
          //                 if (r != null) {
          //                   state.filterTitleList.clear();
          //                   state.filterTitleList.addAll(r);
          //                 }
          //               });
          //             },
          //             child: const Padding(
          //                 padding: EdgeInsets.all(8.0),
          //                 child: Icon(
          //                   Icons.add,
          //                   color: Colors.white,
          //                 )))
          //       ]),
          //       Obx(() {
          //         if (state.currentIndex.value == -1) {
          //           return Container();
          //         }
          //         return Column(children: [
          //           Padding(
          //               padding: const EdgeInsets.all(8.0),
          //               child: Obx(() {
          //                 return CustomTextField(
          //                     value: state.filter.value,
          //                     onChanged: (t) {
          //                       state.filter.value = t;
          //                     },
          //                     style: const TextStyle(color: Colors.white),
          //                     inputDecoration: const InputDecoration(
          //                         isDense: true,
          //                         hintText: "请输入过滤条件",
          //                         hintStyle: TextStyle(
          //                             color: CupertinoColors.systemGrey3),
          //                         contentPadding: EdgeInsets.all(10),
          //                         isCollapsed: true,
          //                         border: UnderlineInputBorder()));
          //               })),
          //           Row(children: [
          //             Expanded(
          //                 child: InkWell(
          //                     onTap: () {
          //                       state.currentIndex.value = -1;
          //                     },
          //                     child: Container(
          //                         padding:
          //                             const EdgeInsets.symmetric(vertical: 12),
          //                         decoration: BoxDecoration(
          //                             color: const Color(0xff3E4C62),
          //                             borderRadius: BorderRadius.circular(5)),
          //                         child: const Center(
          //                             child: Text("取消",
          //                                 style: TextStyle(
          //                                     color: Colors.white)))))),
          //             const SizedBox(width: 5),
          //             Expanded(
          //                 child: InkWell(
          //                     onTap: () {
          //                       state.filterTitleList[state.currentIndex.value]
          //                           .exp.value = state.filter.value;
          //                       state.currentIndex.value = -1;
          //                       state.filter.value = "";
          //                     },
          //                     child: Container(
          //                         padding:
          //                             const EdgeInsets.symmetric(vertical: 12),
          //                         decoration: BoxDecoration(
          //                             color: c_green,
          //                             borderRadius: BorderRadius.circular(5)),
          //                         child: const Center(
          //                             child: Text("查询",
          //                                 style: TextStyle(
          //                                     color: Colors.white))))))
          //           ])
          //         ]);
          //       })
          //     ])),
          Expanded(child: Obx(() {
            return ListView.builder(
                itemCount: state.list.length,
                itemBuilder: (BuildContext context, int index) {
                  SplunkDetailList bean = state.list[index];
                  return GestureDetector(
                    onTap: () {
                      Get.toNamed(RoutePath.warningDetail,
                          arguments: TrafficDetailBean(
                            bean: AiWarningItemList(
                                sip: bean.paSip,
                                spt: bean.paSport,
                                dip: bean.paDip,
                                dpt: bean.paDport,
                                protocols: bean.paProtocal?.isEmpty == true
                                    ? []
                                    : ['${bean.paProtocal}'],
                                startDate: bean.time),
                            isWarnDetail: false,
                            queryCondition: logic.queryCondition.value,
                            type: logic.dateType.value,
                          ));
                    },
                    child: DefaultTextStyle(
                        style: TextStyle(color: c_9EA1A6),
                        child: Container(
                            color: index % 2 == 0
                                ? const Color(0xff233F48)
                                : Colors.transparent,
                            child: SingleChildScrollView(
                                scrollDirection: Axis.horizontal,
                                child: Row(children: [
                                  Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: Text(
                                          "序号:${(logic.page.value - 1) * 10 + index + 1}"
                                              .padLeft(2, "0"))),
                                  Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: Text("等级:${bean.serverity}")),
                                  Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            Text(
                                                "从：${bean.paSip}:${bean.paSport}"),
                                            Text(
                                                "到：${bean.paDip}:${bean.paDip}")
                                          ])),
                                  Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: Text("阻断：${bean.paDenyMentod}"))
                                ])))),
                  );
                });
          })),
          Padding(
              padding: const EdgeInsets.symmetric(horizontal: 10),
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    GestureDetector(
                        onTap: logic.lastPage,
                        child: Padding(
                            padding: const EdgeInsets.all(13),
                            child: Text("上一页",
                                style: TextStyle(color: c_9EA1A6)))),
                    Padding(
                        padding: const EdgeInsets.all(13),
                        child: Obx(() {
                          return Text(
                              "第${logic.page.value}页,共${state.pages.value}页",
                              style: TextStyle(color: c_9EA1A6));
                        })),
                    GestureDetector(
                        onTap: logic.nextPage,
                        child: Padding(
                            padding: const EdgeInsets.all(13),
                            child:
                                Text("下一页", style: TextStyle(color: c_green))))
                  ]))
        ])));
  }
}
